// pages/me/me.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    screenHeight:app.globalData.screenHeight
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    let openId = app.globalData.openId;
    that.getUserData(that,openId)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getUserData (that, openId) {
    app.globalData.wxRequest.requestGet('volunteer/getUserDetail.do', { openId: openId }).then(res => {
      console.log(res);
      if(res.code == '201'){
        wx.showToast({
          title: res.msg,
          icon:'error'
        })
      }
      that.setData({
        userInfo: res.data,
      })
    }).catch(err => {
      wx.showToast({
        title: '请求失败',
        icon: 'error'
      })
    })
  },
  likemajor(){
    wx.navigateTo({
      url: '/pages/bar/me/likemajor/likemajor',
    })
  },
  aboutus(){
    wx.navigateTo({
      url: '/pages/bar/me/aboutus/aboutus',
    })
  },
  attentionSchool(){
    wx.navigateTo({
      url: '/pages/bar/me/attentionSchool/attentionSchool',
    })
  },
  likemajor(){
    wx.navigateTo({
      url: '/pages/bar/me/likemajor/likemajor',
    })
  },
  feedback(){
    wx.navigateTo({
      url: '/pages/bar/me/feedback/feedback',
    })
  },
  myvolunteerList(e){
    if(this.data.userInfo==null){
      wx.showModal({
        title: '提示',
        content: '请先填写个人信息',
        showCancel:false,
        success (res) {
          if (res.confirm) {
            return
          } 
        }
      })
    }else{
      console.log(this.data.userInfo.openId);
      wx.navigateTo({
        url: '/pages/me/myvolunteer/myvolunteer?openid='+this.data.userInfo.openId,
      })
    }
  },
  editUserInfo(e){
    let user = app.globalData.user;
    if(user.isSignUp == 0){
      wx.navigateTo({
        url: '/pages/fill/fillform/fillform',
      })
    }else{
      wx.navigateTo({
        url: '/pages/fill/fillform/fillform?edit=1',
      })
    }
  }
})